home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1985-08-07 | 2.4 KB | 64 lines |
- 10 '**************************************************************************
- 15 '*** ***
- 20 '*** LINEAR EQUATION SOLUTION by TRIDIAGONAL MATRIX ***
- 30 '*** ***
- 40 '**************************************************************************
- 50 '
- 60 ' A maximum of 500 equations can be handled by this routine
- 70 '
- 80 '*** DIMENSION MATRIX ***
- 90 DIM A(500),B(500),C(500),D(500)
- 100 CLS:KEY OFF:LOCATE 10,10
- 110 '
- 120 '*** INPUT NO. of EQUATIONS ***
- 130 '
- 140 INPUT "Number of Equations, N";N ' number of coefficients
- 145 LPRINT "Number of Equations, N ";N
- 150 LPRINT "Tridiagonal Matrix Solution for ";N;"equations
- 160 PRINT:PRINT
- 180 '
- 190 '*** READ COEFFICIENTS ***
- 200 '
- 210 FOR I=1 TO N ' I = row
- 220 PRINT "Input B(";I;")=";:INPUT B(I) 'B= Below Diagonal
- 225 LPRINT "B(";I;")=";B(I)
- 230 PRINT "Input D(";I;")=";:INPUT D(I) 'D= Diagonal Element
- 235 LPRINT "D(";I;")=";D(I)
- 240 PRINT "Input A(";I;")=";:INPUT A(I) 'A= Above Diagonal
- 245 LPRINT "A(";I;")=";A(I)
- 250 PRINT "Input C(";I;")=";:INPUT C(I) 'C= Constant Vector
- 255 LPRINT "C(";I;")=";C(I)
- 260 NEXT I
- 270 '
- 280 ' *** PRINT HEADING ***
- 290 '
- 300 '
- 310 PRINT "Solution to Tridiagonal System of ";N;" equations by elimination."
- 320 LPRINT "Solution to Tridiagonal System of ";N;" equations by elimination."
- 325 PRINT:LPRINT
- 330 '
- 340 '*** PRINT THE NEW MATRIX VALUES ***
- 345 ' Values of Variables will be stored in C Array
- 350 '
- 360 FOR I= 2 TO N
- 370 R=B(I)/D(I-1)
- 380 D(I)=D(I)-R*A(I-1)
- 390 C(I)=C(I)-R*C(I-1)
- 400 NEXT
- 405 '
- 410 '*** BACK SUBSTITUTION ***
- 415 '
- 420 C(N)=C(N)/D(N)
- 430 FOR I=2 TO N
- 440 J=N-I+1
- 450 C(J)=(C(J)-A(J)*C(J+1))/D(J)
- 460 NEXT
- 465 '
- 470 '*** PRINT OUT VALUES OF VARIABLES ***
- 475 '
- 480 FOR I=1 TO N
- 490 PRINT I,C(I)
- 500 LPRINT I,C(I)
- 510 NEXT
- 780 END
-